# coding=utf-8
"""
 ** ATTENTION **
 This code was automatically generated from the file:
 _moc_ast.yaml 

 Do not modify it directly. Modify the configuration file and
 run the generator again.
 ** ** *** ** **

@license: License: LGPL
@copyright: (c) 2009, dogsing.cn
@author: ant-man(Bin Zhao)
"""


import sys


class Node(object):
    """ Abstract base class for AST nodes.
    """
    def children(self):
        """ A sequence of all children that are Nodes
        """
        pass

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        """ Pretty print the Node and all its attributes and
            children (recursively) to a buffer.
            
            file:   
                Open IO buffer into which the Node is printed.
            
            offset: 
                Initial offset (amount of leading spaces) 
            
            attrnames:
                True if you want to see the attribute names in
                name=value pairs. False to only see the values.
            
            showcoord:
                Do you want the coordinates of each Node to be
                displayed.
        """
        pass

    def accept(self, visitor):
        """
        User Visitor pattern to issue some kind of action,
        that binding with the specified type of node
        
        visitor : instance of NodeVisistor or its subclass 
        """
        return visitor.visit(self)

class NodeVisitor(object):
    """ A base NodeVisitor class for visiting c_ast nodes. 
        Subclass it and define your own visit_XXX methods, where
        XXX is the class name you want to visit with these 
        methods.
        
        For example:
        
        class ConstantVisitor(NodeVisitor):
            def __init__(self):
                self.values = []
            
            def visit_Constant(self, node):
                self.values.append(node.value)

        Creates a list of values of all the constant nodes 
        encountered below the given node. To use it:
        
        cv = ConstantVisitor()
        cv.visit(node)
        
        Notes:
        
        *   generic_visit() will be called for AST nodes for which 
            no visit_XXX method was defined. 
        *   The children of nodes for which a visit_XXX was 
            defined will not be visited - if you need this, call
            generic_visit() on the node. 
            You can use:
                NodeVisitor.generic_visit(self, node)
        *   Modeled after Python's own AST visiting facilities
            (the ast module of Python 3.0)
    """
    def visit(self, node):
        """ Visit a node. 
        """
        method = 'visit_' + node.__class__.__name__
        visitor = getattr(self, method, self.generic_visit)
        return visitor(node)

    def generic_visit(self, node):
        """ Called if no explicit visitor function exists for a 
            node. Implements preorder visiting of the node.
        """
        for c in node.children():
            self.visit(c)

class ArithOp(Node):
    def __init__(self, op, left, right, coord=None):
        self.op = op
        if isinstance(op, Node) : op.parent = self
        self.left = left
        if isinstance(left, Node) : left.parent = self
        self.right = right
        if isinstance(right, Node) : right.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        if self.left is not None: nodelist.append(self.left)
        if self.right is not None: nodelist.append(self.right)
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'ArithOp: ')

        if attrnames:
            attrstr = ', '.join('%s=%s' % nv for nv in [("op", repr(self.op))])
        else:
            attrstr = ', '.join('%s' % v for v in [self.op])
        buf.write(attrstr)

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class FuncCall(Node):
    def __init__(self, name, args, coord=None):
        self.name = name
        if isinstance(name, Node) : name.parent = self
        self.args = args
        if isinstance(args, Node) : args.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        if self.name is not None: nodelist.append(self.name)
        if self.args is not None: nodelist.append(self.args)
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'FuncCall: ')

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class UnaryOp(Node):
    def __init__(self, op, expr, coord=None):
        self.op = op
        if isinstance(op, Node) : op.parent = self
        self.expr = expr
        if isinstance(expr, Node) : expr.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        if self.expr is not None: nodelist.append(self.expr)
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'UnaryOp: ')

        if attrnames:
            attrstr = ', '.join('%s=%s' % nv for nv in [("op", repr(self.op))])
        else:
            attrstr = ', '.join('%s' % v for v in [self.op])
        buf.write(attrstr)

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class FileAST(Node):
    def __init__(self, module, coord=None):
        self.module = module
        if isinstance(module, Node) : module.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        for item in module :
            if isinstance(item, Node) : item.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        if self.module is not None: nodelist.extend(self.module)
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'FileAST: ')

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class While(Node):
    def __init__(self, cond, stmt, coord=None):
        self.cond = cond
        if isinstance(cond, Node) : cond.parent = self
        self.stmt = stmt
        if isinstance(stmt, Node) : stmt.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        if self.cond is not None: nodelist.append(self.cond)
        if self.stmt is not None: nodelist.append(self.stmt)
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'While: ')

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class Continue(Node):
    def __init__(self, coord=None):
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        return ()

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'Continue: ')

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class ParamList(Node):
    def __init__(self, params, coord=None):
        self.params = params
        if isinstance(params, Node) : params.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        for item in params :
            if isinstance(item, Node) : item.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        if self.params is not None: nodelist.extend(self.params)
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'ParamList: ')

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class FuncDef(Node):
    def __init__(self, name, params, body, coord=None):
        self.name = name
        if isinstance(name, Node) : name.parent = self
        self.params = params
        if isinstance(params, Node) : params.parent = self
        self.body = body
        if isinstance(body, Node) : body.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        if self.name is not None: nodelist.append(self.name)
        if self.params is not None: nodelist.append(self.params)
        if self.body is not None: nodelist.append(self.body)
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'FuncDef: ')

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class Return(Node):
    def __init__(self, expr, coord=None):
        self.expr = expr
        if isinstance(expr, Node) : expr.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        if self.expr is not None: nodelist.append(self.expr)
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'Return: ')

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class ID(Node):
    def __init__(self, name, coord=None):
        self.name = name
        if isinstance(name, Node) : name.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'ID: ')

        if attrnames:
            attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name))])
        else:
            attrstr = ', '.join('%s' % v for v in [self.name])
        buf.write(attrstr)

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class For(Node):
    def __init__(self, init, cond, next, stmt, coord=None):
        self.init = init
        if isinstance(init, Node) : init.parent = self
        self.cond = cond
        if isinstance(cond, Node) : cond.parent = self
        self.next = next
        if isinstance(next, Node) : next.parent = self
        self.stmt = stmt
        if isinstance(stmt, Node) : stmt.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        if self.init is not None: nodelist.append(self.init)
        if self.cond is not None: nodelist.append(self.cond)
        if self.next is not None: nodelist.append(self.next)
        if self.stmt is not None: nodelist.append(self.stmt)
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'For: ')

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class RelOp(Node):
    def __init__(self, op, left, right, coord=None):
        self.op = op
        if isinstance(op, Node) : op.parent = self
        self.left = left
        if isinstance(left, Node) : left.parent = self
        self.right = right
        if isinstance(right, Node) : right.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        if self.left is not None: nodelist.append(self.left)
        if self.right is not None: nodelist.append(self.right)
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'RelOp: ')

        if attrnames:
            attrstr = ', '.join('%s=%s' % nv for nv in [("op", repr(self.op))])
        else:
            attrstr = ', '.join('%s' % v for v in [self.op])
        buf.write(attrstr)

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class ObjectRef(Node):
    def __init__(self, name, field, coord=None):
        self.name = name
        if isinstance(name, Node) : name.parent = self
        self.field = field
        if isinstance(field, Node) : field.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        if self.name is not None: nodelist.append(self.name)
        if self.field is not None: nodelist.append(self.field)
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'ObjectRef: ')

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class Constant(Node):
    def __init__(self, type, value, coord=None):
        self.type = type
        if isinstance(type, Node) : type.parent = self
        self.value = value
        if isinstance(value, Node) : value.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'Constant: ')

        if attrnames:
            attrstr = ', '.join('%s=%s' % nv for nv in [("type", repr(self.type)), ("value", repr(self.value))])
        else:
            attrstr = ', '.join('%s' % v for v in [self.type, self.value])
        buf.write(attrstr)

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class LogicalOp(Node):
    def __init__(self, op, left, right, coord=None):
        self.op = op
        if isinstance(op, Node) : op.parent = self
        self.left = left
        if isinstance(left, Node) : left.parent = self
        self.right = right
        if isinstance(right, Node) : right.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        if self.left is not None: nodelist.append(self.left)
        if self.right is not None: nodelist.append(self.right)
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'LogicalOp: ')

        if attrnames:
            attrstr = ', '.join('%s=%s' % nv for nv in [("op", repr(self.op))])
        else:
            attrstr = ', '.join('%s' % v for v in [self.op])
        buf.write(attrstr)

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class Assignment(Node):
    def __init__(self, op, lvalue, rvalue, coord=None):
        self.op = op
        if isinstance(op, Node) : op.parent = self
        self.lvalue = lvalue
        if isinstance(lvalue, Node) : lvalue.parent = self
        self.rvalue = rvalue
        if isinstance(rvalue, Node) : rvalue.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        if self.lvalue is not None: nodelist.append(self.lvalue)
        if self.rvalue is not None: nodelist.append(self.rvalue)
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'Assignment: ')

        if attrnames:
            attrstr = ', '.join('%s=%s' % nv for nv in [("op", repr(self.op))])
        else:
            attrstr = ', '.join('%s' % v for v in [self.op])
        buf.write(attrstr)

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class Break(Node):
    def __init__(self, coord=None):
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        return ()

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'Break: ')

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class ForEach(Node):
    def __init__(self, ref, list, stmt, coord=None):
        self.ref = ref
        if isinstance(ref, Node) : ref.parent = self
        self.list = list
        if isinstance(list, Node) : list.parent = self
        self.stmt = stmt
        if isinstance(stmt, Node) : stmt.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        if self.ref is not None: nodelist.append(self.ref)
        if self.list is not None: nodelist.append(self.list)
        if self.stmt is not None: nodelist.append(self.stmt)
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'ForEach: ')

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class CollectionRef(Node):
    def __init__(self, name, subscript, coord=None):
        self.name = name
        if isinstance(name, Node) : name.parent = self
        self.subscript = subscript
        if isinstance(subscript, Node) : subscript.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        if self.name is not None: nodelist.append(self.name)
        if self.subscript is not None: nodelist.append(self.subscript)
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'CollectionRef: ')

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class Compound(Node):
    def __init__(self, stmts, coord=None):
        self.stmts = stmts
        if isinstance(stmts, Node) : stmts.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        if not stmts : return
        for item in stmts :
            if isinstance(item, Node) : item.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        if self.stmts is not None: nodelist.extend(self.stmts)
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'Compound: ')

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

class If(Node):
    def __init__(self, cond, iftrue, iffalse, coord=None):
        self.cond = cond
        if isinstance(cond, Node) : cond.parent = self
        self.iftrue = iftrue
        if isinstance(iftrue, Node) : iftrue.parent = self
        self.iffalse = iffalse
        if isinstance(iffalse, Node) : iffalse.parent = self
        self.coord = coord
        if isinstance(coord, Node) : coord.parent = self
        self.parent = None

    def children(self):
        nodelist = []
        if self.cond is not None: nodelist.append(self.cond)
        if self.iftrue is not None: nodelist.append(self.iftrue)
        if self.iffalse is not None: nodelist.append(self.iffalse)
        return tuple(nodelist)

    def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
        lead = ' ' * offset
        buf.write(lead + 'If: ')

        if showcoord and self.coord:
            buf.write(' (at %s)' % self.coord)
        buf.write('\n')

        for c in self.children():
            c.show(buf, offset + 2, attrnames, showcoord)

